package com.cch.cooperation.api.feedback.service;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson2.JSON;
import com.cch.cooperation.api.feedback.dto.FeedbackAddDTO;
import com.cch.cooperation.biz.common.util.BeanUtilEx;
import com.cch.cooperation.common.util.SnowflakeIdUtil;
import com.cch.cooperation.dao.feedback.mapper.FeedbackMapper;
import com.cch.cooperation.dao.feedback.model.Feedback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;

/**
 * 反馈业务处理
 *
 * @author cch
 */
@Slf4j
@Service
public class FeedbackServiceImpl {

    @Resource
    private FeedbackMapper mapper;

    public void add(@Valid FeedbackAddDTO req) {
        Feedback feedback = BeanUtilEx.copy(req, Feedback.class);
        feedback.setId(SnowflakeIdUtil.getIdStr());
        if (CollUtil.isNotEmpty(req.getFiles())) {
            feedback.setFiles(JSON.toJSONString(req.getFiles()));
        }
        feedback.setCreateTime(new Date());
        mapper.insert(feedback);
    }
}
